package photostock.model;

import java.io.Serializable;
import java.util.Hashtable;
import java.util.Map;
import java.util.Properties;
import java.util.Vector;

public class ItemInfo implements Serializable {
	
	private static final long serialVersionUID = 20090501L;
	private Properties p;
	private boolean exists;

	public ItemInfo(String neededFields) {
		for (String s : neededFields.split(","))
			p.setProperty(s, "");
	}
	
	public ItemInfo(String neededFields, Vector<Hashtable<String, Object>> result) {
		if (result.size() > 0) {
			exists = true;
			p = new Properties();
			for (Map.Entry<String, Object> entry : result.elementAt(0).entrySet())
				if (neededFields.indexOf(entry.getKey()) != -1) 
					p.setProperty(entry.getKey(), entry.getValue().toString());
		} else exists = false;
	}
	
	public ItemInfo(String s, Hashtable<String, Object> infos) {
		if (infos.entrySet().size() > 0) {
			exists = true;
			p = new Properties();
			for (Map.Entry<String, Object> entry : infos.entrySet())
				if (s.indexOf(entry.getKey()) != -1) 
					p.setProperty(entry.getKey(), entry.getValue().toString());
		} else exists = false;
	}
	
	
	public boolean exists() {
		return exists;
	}
	
	public String get(String s) {
		return p.getProperty(s) == null ? "" : p.getProperty(s); 
	}
	
	public void set(String property, String value) {
		p.setProperty(property, value);
	}
	
}
